package com.lemon.smartsafetynew.ui.activity.hidden;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafetynew.ui.fragment.hidden.SafeHiddenDoingFragment;
import com.lemon.smartsafetynew.ui.fragment.hidden.SafeHiddenDoneFragment;


import butterknife.Bind;

/**
 * Created by Andrew on 2017/7/25.
 */

public class SafeHiddenDangerHomeActivity extends SwipeBackActivity {

    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.viewPager)
    ViewPager viewPager;

    @Override
    protected void initTitle() {
        this.setBarTitle(getString(R.string.work_options_main_2));
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_viewpage_tab_layout;
    }


    @Override
    protected void initViews() {
        super.initViews();

        // ======= 该变指示栏的长度 =======
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                setIndicator(tabLayout, 10, 10); //左右各缩进5dp
            }
        });

        // ======= 该变指示栏的长度 =======
        viewPager.setAdapter(new HiddenViewpagerAdapter(getSupportFragmentManager()));
        tabLayout.setupWithViewPager(viewPager);

    }

    private class HiddenViewpagerAdapter extends FragmentStatePagerAdapter {

        public HiddenViewpagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return SafeHiddenDoingFragment.newInstance();
                case 1:
                    return SafeHiddenDoneFragment.newInstance();
                default:
                    return SafeHiddenDoingFragment.newInstance();
            }
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return getString(R.string.hidden_home_tab_1);
                case 1:
                    return getString(R.string.hidden_home_tab_2);
            }
            return null;
        }

    }

}
